package com.yc.yyds.servlet;

import com.google.gson.Gson;
import com.yc.yyds.Bean.Result;
import com.yc.yyds.biz.BizException;
import com.yc.yyds.biz.UserLoginBiz;

import javax.servlet.*;
import javax.servlet.http.*;
import javax.servlet.annotation.*;
import java.io.IOException;
import java.util.Map;

@WebServlet(name = "IdLoginServlet", value = "/IdLoginServlet.s")
public class IdLoginServlet extends HttpServlet {
    UserLoginBiz biz = new UserLoginBiz();
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
    }

    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {


        String userzh = request.getParameter("userzh");
        String pwd = request.getParameter("pwd");
        Result result;
        Gson gson = new Gson();
        try {
            Map<String, Object> data = biz.userLogin(userzh, pwd);
            request.getSession().setAttribute("userMsg",data);
            result = new Result(1,"登录成功",data);
            String json = gson.toJson(result);
            response.getWriter().append(json);
        } catch (BizException e) {
            e.printStackTrace();
            result = new Result(0,e.getMessage(),null);
            String json = gson.toJson(result);
            response.getWriter().append(json);
        }
    }
}
